TextField |
The text field class implements a single line text entry area. TextField is a sub class of textcomponent. |
WRITE A PROGRAM ON TEXTFIELD.
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class Text extends Applet implements ActionListener
{
TextField n,p;
public void init()
{
Label na=new Label("Name: ",Label.RIGHT);
Label pa=new Label("PassWord: ",Label.RIGHT);
n=new TextField(12);
p=new TextField(8);
p.setEchoChar('*');
add(n);
add(p);
add(na);
add(pa);
n.addActionListener(this);
p.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
repaint();
}
public void paint(Graphics g)
{
g.drawString("Name: "+n.getText(),6,60);
g.drawString("Password: "+n.getText(),6,100);
}
}
/*<applet code=Text height=150 width=380>
</applet>*/
TextArea |
Using text area we can include multiple lines of the text like an editor |
WRITE A PROGRAM ON TEXT AREA.
import java.awt.*;
import java.applet.*;
public class Area extends Applet
{
String s;
public void init()
{
s=" HELLO DEAR STUDENTS WELCOME TO VISION COMPUTERS.\n"+
" THIS NOTES CAN BE PREPARED VISION COMPUTERS.";
TextArea text=new TextArea(s,10,60);
add(text);
}
}
/*<applet code=Area width=400 height=100>
</applet>*/